package com.franklin.java.api.psi.data.resolver;

import com.franklin.java.api.psi.data.PsiData;
import com.franklin.plugins.common.utils.PatternUtils;
import com.intellij.psi.PsiElement;

import java.util.Objects;

/**
 * 基本数据类型解析器
 * @author Franklin
 * @since 2021/08/15/ 21:19
 */
public class BasicTypeResolver implements PsiDataResolver {
    @Override
    public PsiData resolve(String name, String value, PsiElement dataElement) {
        String type = "String";
        String val = value;
        PsiElement psiElement = dataElement.getNavigationElement();
        String typeFullName = null;
        if (PatternUtils.isStringValue(value)) {
            type = "String";
            typeFullName = "java.lang.String";
        } else if (PatternUtils.isIntValue(value)) {
            type = "Integer";
            typeFullName = "java.lang.Integer";
        } else if (PatternUtils.isLongValue(value)) {
            type = "Long";
            typeFullName = "java.lang.Long";
        } else if (PatternUtils.isFloatValue(value)) {
            type = "Float";
            typeFullName = "java.lang.Float";
        } else if (PatternUtils.isDoubleValue(value)) {
            type = "Double";
            typeFullName = "java.lang.Double";
        } else if (PatternUtils.isBooleanValue(value)) {
            type = "Boolean";
            typeFullName = "java.lang.Boolean";
        }

        if (Objects.isNull(typeFullName)){
            return null;
        }
        return new PsiData(type, val, psiElement, typeFullName, dataElement);
    }
}
